 /*******************************************************************************
* File Name: motor_estimator.h
* Version 1.00
*
* Description:
*  This file provides the source code to the API for the Sequencing Successive
*  Approximation ADC Component Component.
*
* Note:
*
********************************************************************************
* Copyright 2010-2019, CMS Semiconductor Corporation.  All rights reserved.
* You may use this file only in accordance with the license, terms, conditions,
* disclaimers, and limitations in the end user license agreement accompanying
* the software package with which this file was provided.
*******************************************************************************/

#ifndef __MOTOR_ESTIMATOR_H__
#define __MOTOR_ESTIMATOR_H__

#ifdef __cplusplus
extern "C"
{
#endif

/*****************************************************************************/
/* Include files */
/*****************************************************************************/
#include "filter.h"
#include "coordinate_transforms.h"

/*****************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/*****************************************************************************/

						
/*****************************************************************************/
/* Global type definitions ('typedef') */
/*****************************************************************************/
typedef struct {
	int32_t Q8_Ealpha;
	int32_t Q8_Ebeta;
	int32_t Q8_Ed;
	int32_t Q8_Eq;
	int32_t Q8_IalphaPre;
	int32_t Q8_IbetaPre;
	int32_t Q8_ValphaPre;
	int32_t Q8_VbetaPre;
	int32_t Q8_di_dt_max;
	int32_t Q8_di_dt_min;
	stc_OneOrderLPF_t d_LPFKPar;
	stc_OneOrderLPF_t q_LPFKPar;
	int32_t Q8_Edf;
	int32_t Q8_Eqf;
	int32_t Q8_Edlf;
	int32_t Q12_Cos;
	int32_t Q12_Sin;
	int32_t Q12_CosPre;
	int32_t Q12_SinPre;

	int32_t Q8_Res;
	int32_t Q8_Ls_dt;
	int32_t Q8_dLd_dt;
	int32_t Q12_Ld_Lq;
	int32_t Q12_inv_Ke;
	int32_t DeltaThetaKTs;
	int32_t DeltaThetaTs;

	uint8_t Ke_Chg_En;        
	int32_t Ke_Reg_Cnt;
	int32_t Angle;
	int32_t Q8_Estimate_Hz;
	int32_t Q8_Estimate_Hzf;
	stc_OneOrderLPF_t  OmegaLPFK;
	stc_OneOrderLPF_t  EdLPFK;
} stc_PLLEstimator_t;

/*****************************************************************************/
/* Global variable declarations ('extern', definition in C source) */
/*****************************************************************************/


/*****************************************************************************/
/* Global function prototypes ('extern', definition in C source) */
/*****************************************************************************/
extern void Postion_Estimate(stc_PLLEstimator_t *EstimPar, stc_abAxis_t *Motor_2sVoltage, stc_abAxis_t *Motor_2sCurrent);


#ifdef __cplusplus
}
#endif

#endif /* __MOTOR_ESTIMATOR_H__ */

